import BuffUtil from '@/BuffUtil';
import UnitStateUtil from '@/UnitStateUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 死亡打击
 */
export default class DK_DeathHit extends AbilityBase {
    static instance: DK_DeathHit;
    buffType: AppBuffType = {
        id: 'buff_DK_DeathHit',
        name: this.abilityName,
        ubertip: this.abilityData.Ubertip,
        art: this.art,
        dur: 12,
        targetAttach: 'weapon',
        targetArt: 'Abilities\\Spells\\Items\\OrbDarkness\\OrbDarkness.mdl',
    };
    constructor(id: string) {
        super(id);
        DK_DeathHit.instance = this;
        this.init();
        se.onUnitSpellEffect(this.spellEffect.bind(this), this.id);
        EventManager.onBeforApplyAttack(this.attackEffect.bind(this));
    }
    attackEffect(d: DamageEventData) {
        let buff = BuffUtil.getUnitBuff(d.source, this.buffType.id);
        if (buff == null) return;
        let lv = this.getAbilityLevel(d.source);
        let life = UnitStateUtil.getMaxLife(d.source);
        let dmg = (0.05 + lv * 0.05) * life;
        d.initDamage += dmg;
        d.isCrited = true;
        buff.destroy();
        DamageSystemInstance.applyHeal(d.source, d.source, life * 0.075, this.id);
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Orc\\Devour\\DevourEffectArt.mdl', d.target, 'origin'));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    spellEffect() {
        this.cast(GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), GetTriggerUnit(), GetTriggerUnit());
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.addBuff(target, this.buffType.id, source);
        BuffCommon.addBuff({
            target: source,
            caster: source,
            ablityId: this.id,
            buffTypeId: this.buffType.id,
        });
        UnitCommon.普攻冷却(target);
    }
}
